{extend name="iframe" /}
{block name="body"}
<div class="layui-card">
    <div class="layui-card-body">
        <input type="hidden" id="id" name="id" value="{$data.id|default=''}" />
        <button type="button" class="layui-btn layui-btn-normal layui-btn-position collectImport"><i class="fa fa-file-o"></i> 请选择文件导入</button>
    </div>

    <hr />
    <div id="importInfo" style="display: none;">
        <input type="hidden" id="batchNo" name="batchNo" value="{$data.batch_no|default=''}" />
        <table>
            <tr>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td><label>批次号：</label></td>
                <td><label id="batch">{$data.batch_no|default=''}</label></td>
                <td></td>
                <td><label>重复数量：</label></td>
                <td><label id="repeatNum">{$data.repeat_num|default='0'}</label></td>
                <td></td>
            </tr>
            <tr>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td><label>失败数量：</label></td>
                <td><label id="failNum">{$data.fail_num|default='0'}</label></td>
                <td></td>
                <td><label>成功数量：</label></td>
                <td><label id="successNum">{$data.success_num|default='0'}</label></td>
                <td></td>
            </tr>
            <tr>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
            </tr>
            <tr>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td></td>
                <td></td>
                <td><button type="button" onclick="sureImport()" class="layui-btn layui-btn-normal layui-btn-position"><i class="fa fa-file-o"></i> 导入</button>
                <td></td>
                <td><button type="button" onclick="skipImport()" class="layui-btn layui-btn-normal layui-btn-position"><i class="fa fa-file-o"></i> 撤回</button>
                <td></td>
            </tr>
        </table>
    </div>

</div>
{/block}
{block name="js"}
<script>
    var index = 0
    upload.render({
        elem: '.collectImport',
        url: '/admin/metadata/importData?id=' + $('#id').val(),
        accept: 'file', // 普通文件
        before: function () {
            index = layer.msg('上传中，请稍候', {
                icon: 16,
                time: false,
                shade: 0.3
            });
        },
        done: function (result) {
            layer.close(index);
            // 上传完毕回调
            if (result.code === 1) {
                layer.msg("导入成功");

                var resData = result.data;
                $('#batchNo').val(resData.batch_no);
                $('#batch').html(resData.batch_no);
                $('#repeatNum').html(resData.repeat_num);
                $('#failNum').html(resData.fail_num);
                $('#successNum').html(resData.success_num);

                document.getElementById("importInfo").style.display="";//显
            } else {
                layer.msg(result.msg);
            }
        }
    });


    function sureImport() {
        var id = $('#id').val();
        if (id === '' || id === null || id === undefined) {
            layer.msg("类型错误");
        }
        var batchNo = $('#batchNo').val();
        if (batchNo === '' || batchNo === null || batchNo === undefined) {
            layer.msg("请先导入数据");
        }
        var index = layer.msg('导入中，请稍候', {
            icon: 16,
            time: false,
            shade: 0.3
        });
        $.ajax({
            url: '/admin/metadata/sureImport?id=' + id + '&batchNo=' + batchNo,
            type: 'post',
            dataType: 'json',
            success: function (result) {
                layer.close(index);
                if (result.code === 1) {
                    layer.msg('导入成功');
                    parent.location.href = result.url;
                }
            },
            error: function (xhr, state, errorThrown) {
                layer.close(index);
                layer.msg(state + '：' + errorThrown);
            }
        });
    }

    function skipImport() {
        var id = $('#id').val();
        if (id === '' || id === null || id === undefined) {
            layer.msg("类型错误");
        }
        var batchNo = $('#batchNo').val();
        if (batchNo === '' || batchNo === null || batchNo === undefined) {
            layer.msg("请先导入数据");
        }
        $.ajax({
            url: '/admin/metadata/skipImport?id=' + id + '&batchNo=' + batchNo,
            type: 'post',
            dataType: 'json',
            success: function (result) {
                if (result.code === 1) {
                    layer.msg('撤回成功');
                    parent.location.href = result.url;
                }
            },
            error: function (xhr, state, errorThrown) {
                layer.msg(state + '：' + errorThrown);
            }
        });
    }

</script>
{/block}